package com.adteam.xmap.manager.impl;

import java.util.Iterator;
import java.util.List;

import junit.framework.TestCase;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.adteam.xmap.entity.Administrator;
import com.adteam.xmap.manager.AdministratorManager;

public class AdministratorManagerImplTest extends TestCase {
	
	private AdministratorManager administratorManager;
	
	@Override
	protected void setUp() throws Exception {
		BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext-*.xml");
		administratorManager = (AdministratorManager)factory.getBean("administratorManager");
	}

	public void testAddAdministrator() {
		
		Administrator administrator = new Administrator();
		
		administrator.setAccount("С2");
		administrator.setPassword("123");
		
		
		administratorManager.addAdministrator(administrator);
	}

	public void testDelAdministrator() {
		administratorManager.delAdministrator(1);
	}

	public void testFindAdministratorById() {
		System.err.println(administratorManager.findAdministratorById(1).getAccount());
	}

	public void testFindAllAdministrators() {
		List administrators = administratorManager.findAllAdministrators();
		
		for (Iterator iterator = administrators.iterator(); iterator.hasNext();) {
			Administrator administrator = (Administrator) iterator.next();
			System.err.println(administrator.getAccount());
		}
	}

	public void testUpdateAdministrator() {
		Administrator administrator = new Administrator();
		administrator.setId(1);
		administrator.setAccount("С");
		administrator.setPassword("123");
		
		
		administratorManager.updateAdministrator(administrator);
	}

}
